package com.anivia.common.web.satoken;

import cn.dev33.satoken.stp.StpInterface;
import cn.hutool.core.collection.CollUtil;
import com.anivia.common.web.satoken.admin.StpAdminUtil;
import com.anivia.common.web.satoken.user.StpUserUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自定义权限验证接口扩展
 *
 * @author wangj
 */
@Slf4j
@Component
public class StpInterfaceImpl implements StpInterface {
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        List<String> permissionList = null;
        if (StpAdminUtil.getLoginType().equalsIgnoreCase(loginType)) {
            // 获取权限 TODO
            permissionList = (List<String>) StpAdminUtil.getExtra("permission");
        }

        if (StpUserUtil.getLoginType().equalsIgnoreCase(loginType)) {
            // 获取权限 TODO
            permissionList = (List<String>) StpUserUtil.getExtra("permission");
        }
        log.info("loginId={},权限列表：{}", permissionList);
        return CollUtil.emptyIfNull(permissionList);
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        List<String> roleList = null;
        if (StpAdminUtil.getLoginType().equalsIgnoreCase(loginType)) {
            // 获取角色 TODO
            roleList = (List<String>) StpAdminUtil.getExtra("role");
        }
        if (StpUserUtil.getLoginType().equalsIgnoreCase(loginType)) {
            // 获取角色 TODO
            roleList = (List<String>) StpUserUtil.getExtra("role");
        }
        log.info("loginId={},角色列表：{}", roleList);
        return CollUtil.emptyIfNull(roleList);
    }
}
